package chapter4;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class BaiduByName {

    public static void main(String[] args) {
        InetAddress address = null;
        try {
            //根据域名查IP
            address = InetAddress.getByName("www.baidu.com");
            System.out.println(address);
            //根据IP查域名，没有就显示IP
            address = InetAddress.getByName("110.242.68.4");
            System.out.println(address);
            //获取域名的所有IP
            InetAddress[] allAddresses = InetAddress.getAllByName("www.baidu.com");
            for (InetAddress address1: allAddresses){
                System.out.println(address1);
            }

        } catch (UnknownHostException e) {
            System.out.println("Could not find www.baidu.com");
        }
    }

}
